import {Injectable} from '@angular/core';
import {adSystemApiUrl} from '../../../../../config/api';
import {HttpService} from '../../../../lib/service/http.service';


@Injectable()
export class NewSpellService {

  constructor(private httpService: HttpService) {
  }

  // 获取分组列表
  getGroupList(applet_uuid: number) {
    const url = `${adSystemApiUrl}/v1/member/applet_goods_category/list?applet_uuid=${applet_uuid}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 获取商品列表
  getGoodsList(page: number,
               pageSize: number,
               applet_goods_category_id?: number,
               status?: string, keyword?: string,
               order?: string,
             ) {
    const _applet_goods_category_id = applet_goods_category_id || '',
      _status = (status === '选择商品状态' ? '' : status) || '',
      _keyword = keyword || '';
    const _order = (order === 'none' ? '' : order) || '';
    const url = `${adSystemApiUrl}/v1/member/goods/list` +
      `?applet_goods_category_id=${_applet_goods_category_id}` +
      `&order=${_order}&status=${_status}&keyword=${_keyword}&page=${page}&pageSize=${pageSize}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 获取商品详情
  getGoodsDetail(applet_uuid: string, id: number) {
    const url = `${adSystemApiUrl}/v1/applet/goods/get_goods_info?applet_uuid=${applet_uuid}&id=${id}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 获取商品sku
  getGoodsSkuList(goods_id: number) {
    const url = `${adSystemApiUrl}/v1/member/goods_sku/list?goods_id=${goods_id}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 获取商品绑定了哪些分类
  getbindListAll(goods_id) {
    const url = `${adSystemApiUrl}/v1/member/applet_goods_category_relation/bindListAll?goods_id=${goods_id}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 新建活动
  postAddActivity(data) {
    const url = `${adSystemApiUrl}/v2/member/activity/add`;
    return this.httpService.httpPostAuth(url, data).map(rs => rs);
  }

  // 活动商品添加
  postAddActivityGoods(data) {
    const url = `${adSystemApiUrl}/v2/member/activity_goods/add`;
    return this.httpService.httpPostAuth(url, data).map(rs => rs);
  }

  // 活动管理列表
  getActivityList(page,
                  pageSize,
                  applet_uuid,
                  stage,
                  name,
                  status) {
    const url = `${adSystemApiUrl}/v2/member/activity/list?page=${page}&pageSize=${pageSize}&applet_uuid=${applet_uuid}&stage=${stage}&type=2&name=${name||''}&status=${status||''}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 获取活动详情
  getActivityInfo(applet_uuid, id) {
    const url = `${adSystemApiUrl}/v2/member/activity/info?applet_uuid=${applet_uuid}&id=${id}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 编辑活动
  postEditActivity(data) {
    const url = `${adSystemApiUrl}/v2/member/activity/edit`;
    return this.httpService.httpPostAuth(url, data).map(rs => rs);
  }

  // 编辑活动商品
  postEditGoods(data) {
    const url = `${adSystemApiUrl}/v2/member/activity_goods/edit`;
    return this.httpService.httpPostAuth(url, data).map(rs => rs);
  }

  // 修改活动状态
  postActivityStatus(applet_uuid, id, status) {
    const data = {applet_uuid: applet_uuid, id: id, status: status};
    const url = `${adSystemApiUrl}/v2/member/activity/status`;
    return this.httpService.httpPostAuth(url, data).map(rs => rs);
  }

  // 修改活动日期
  postChangeTime(data) {
    const url = `${adSystemApiUrl}/v2/member/activity/change_time`;
    return this.httpService.httpPostAuth(url, data).map(rs => rs);
  }

  // 删除活动
  delActivity(applet_uuid, id) {
    const data = {applet_uuid: applet_uuid, id: id};
    const url = `${adSystemApiUrl}/v2/member/activity/del`;
    return this.httpService.httpPostAuth(url, data).map(rs => rs);
  }
}
